package lookie.app.ui.totd;

import lookie.app.ui.app.SettingsIds;

import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
import org.springframework.richclient.settings.Settings;
import org.springframework.richclient.settings.SettingsException;
import org.springframework.richclient.settings.SettingsManager;

public class TipOfTheDayCommand extends ApplicationWindowAwareCommand {

	private TipOfTheDayBox tipOfTheDayBox;

	private SettingsManager settingsManager;

	public TipOfTheDayCommand() {
		super("tipOfTheDayCommand");
	}

	public void setTipOfTheDayBox(TipOfTheDayBox tipOfTheDayBox) {
		this.tipOfTheDayBox = tipOfTheDayBox;
	}

	public void setSettingsManager(SettingsManager settingsManager) {
		this.settingsManager = settingsManager;
	}

	@Override
	protected void doExecuteCommand() {
		Settings userSettings = null;
		try {
			userSettings = settingsManager.getUserSettings();
		} catch (SettingsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		boolean showTips = userSettings.getBoolean(SettingsIds.SHOW_TIPS);

		tipOfTheDayBox.setShowTipsSelected(showTips);
		tipOfTheDayBox.display(getApplicationWindow().getControl());
		showTips = tipOfTheDayBox.isShowTipsSelected();
		userSettings.setBoolean(SettingsIds.SHOW_TIPS, showTips);
	}

}
